-- debug stuff
-- 2007 ashror@gilneas
-- part of the konglomerat addon

------------------------------------------------------------------------------
-- debug print
------------------------------------------------------------------------------
function konglomerat_debugp(msg)
	if(msg==nil) then msg = "nil"; end
	if(KGM_DEBUG) then
		konglomerat_ChannelMsg(
			konglomerat_GetChannelChatFrame(KGM_DATA_CHANNEL),
			">> DEBUG: "..msg);
	end
end;

------------------------------------------------------------------------------
-- list table contents 
------------------------------------------------------------------------------
function konglomerat_listtablecontents(tbl,lvl)

	if(not lvl or lvl==nil) then lvl = 0; end
	
	local spref = "";
	for i=1, lvl, 1 do spref = spref.."     ++ "; end

	if(type(tbl)~="table") then
		konglomerat_debugp("not a table");
		return;
	end

	if(lvl==0) then
		konglomerat_debugp("table size: "..#tbl);
	end

	-- std table
	for i,v in ipairs(tbl) do
		konglomerat_debugp(spref..i..":"..tostring(v));
		if(type(v)=="table") then
			konglomerat_listtablecontents(v,lvl+1);
		end
	end
	
	-- associative
	for k,v in pairs(tbl) do
		konglomerat_debugp(spref..tostring(k).."="..tostring(v));
		if(type(v)=="table") then
			konglomerat_listtablecontents(v,lvl+1);
		end
	end

end;

------------------------------------------------------------------------------
-- save debug data
------------------------------------------------------------------------------
function konglomerat_save_debugdata(name,data)
	if(not konglomerat_debug_data or konglomerat_debug_data==nil) then
		konglomerat_debug_data = {};
	end

	konglomerat_debug_data[name] = {};
	konglomerat_debug_data[name] = data;

	konglomerat_debugp("The data will be written after next logout.");
end;

